<!DOCTYPE html>
<html lang=cmn-Hans>

<head>
    <title>登录</title>
    {{template "admin/partials/html-head.html"}}
</head>

<body class="hold-transition login-page">
    <div class="login-box">
        <div class="login-logo">
            <a href="/admin"><b>Admin</b>LTE</a>
        </div>
        <!-- /.login-logo -->
        <div class="login-box-body">
            <p class="login-box-msg">登录</p>
            <form onsubmit="return false">
                <div class="form-group has-feedback">
                    <input type="text" class="form-control" name="mobile" value="13100000001" placeholder="手机或邮箱">
                    <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                </div>
                <div class="form-group has-feedback">
                    <input type="password" class="form-control" name="password" value="metal0001"
                        placeholder="Password">
                    <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                </div>
                <div class="row">
                    <!-- <div class="col-xs-8">
                        <div class="checkbox icheck">
                            <label>
                                <input type="checkbox" name="remember">记住
                            </label>
                        </div>
                    </div> -->
                    <!-- /.col -->
                    <div class="col-xs-4">
                        <button type="submit" class="btn btn-primary btn-block btn-flat" id="login">登陆</button>
                    </div>
                    {{if eq .status 1}}
                    <div class="col-xs-8">
                        <span>验证成功，请登录</span>
                    </div>
                    {{end}}
                    <!-- /.col -->
                </div>
            </form>
            <a href="#" id="forget-password">忘记密码</a><br>
            <a href="/admin/page/register" class="text-center">注册</a>
        </div>
        <!-- /.login-box-body -->
    </div>
    <!-- /.login-box -->

    <!-- jQuery 3 -->
    <script src="../../static/bower_components/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap 3.3.7 -->
    <script src="../../static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- iCheck -->
    <script src="../../static/plugins/iCheck/icheck.min.js"></script>
    <script>
        $(function () {
            $('input').iCheck({
                checkboxClass: 'icheckbox_square-blue',
                radioClass: 'iradio_square-blue',
                increaseArea: '20%' /* optional */
            });
            $("form").on('submit', function () {
                login();
            });
            function login() {
                let remember = $("input[name=remember]").is(':checked');
                $.ajax({
                    url: '/admin/api/to-login',
                    type: 'post', //GET
                    async: true,    //或false,是否异步
                    data: {
                        mobile: $("input[name=mobile]").val(),
                        password: $("input[name=password]").val(),
                        remember: remember,
                    },
                    timeout: 5000,    //超时时间
                    dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                    beforeSend: function (xhr) {
                        console.log('发送前')
                    },
                    success: function (data, textStatus, jqXHR) {
                        if (data.code !== 0) {
                            alert(data.msg)
                            return
                        }
                        document.cookie = 'token=' + data.data;
                        location.href = "/admin/page/welcome"
                    },
                    error: function (xhr, textStatus) {
                        console.log('错误')
                    },
                    complete: function () {
                        console.log('结束')
                    }
                })
            }
            $("#forget-password").click(function () {

            })
        });
    </script>
</body>

</html>